import { Connection } from 'mongoose';
import { getInstance } from '../../db';
import { loveImageSchema } from '../../schemas/loveImageSchema';

// 新增图片
export async function addImageService(params: IAnyObject):Promise<IAnyObject> {
  const db: Connection = await getInstance();

  const loveImageModel = db.model('loveImageSchema', loveImageSchema);

  const result = await loveImageModel.create(params);

  return result;
}


// 删除图片信息
export const deleteImgService = async (id: string) => {
  const db: Connection = await getInstance();
  const organizationModel = db.model('organizationModel', loveImageSchema);

  const result = await organizationModel.remove({ _id: id });

  return result;
}

// 获取所有的图片
export const getImgListService = async (): Promise<IAnyObject> => {
  const db: Connection = await getInstance();
  const loveImageModel = db.model('loveImageSchema', loveImageSchema);

  // 懒得搞分页了，操
  const result = await loveImageModel.find();

  return result;
}